import { positionList } from "@/api";
import * as layout from "@/router/layouts";

export const gender = () => {
  return [
    {
      value: 0,
      label: "全部"
    },
    {
      value: 1,
      label: "男"
    },
    {
      value: 2,
      label: "女"
    }
  ];
};
export const isAdminList = () => {
  return [
    { value: 0, label: "否" },
    { value: 1, label: "是" }
  ];
};

export const layoutList = () => {
  let list = [{ value: "", label: "无" }];
  Object.values(layout).forEach(i => {
    list.push({ value: i.name, label: i.meta.title });
  });
  return list;

  //   [
  //     { value: "", label: "无" },
  //     { value: "Dashboard", label: "大屏" },
  //     { value: "System", label: "系统管理" },
  //     { value: "Property", label: "资产管理" },
  //     { value: "Work", label: "工单管理" },
  //     { value: "Strategy", label: "策略管理" },
  //     { value: "Customer", label: "客服管理" },
  //     { value: "SparePart", label: "备件管理" },
  //     { value: "Emergency", label: "应急管理" },
  //     { value: "AlarmWarning", label: "报警预警" },
  //     { value: "Wiki", label: "知识库管理" },
  //     { value: "Visualization", label: "可视化管理" },
  //   ];
};

const search = selectPosition => {
  return () => {
    positionList({
      name: "",
      pageNo: 1,
      pageSize: 100
    }).then(res => {
      selectPosition.options = res.data.dataList.map(i => {
        return {
          ...i,
          value: i.name
        };
      });
    });
  };
};

export const searchRule = () => {
  const selectPosition = {
    type: "select",
    field: "position",
    title: "职务",
    options: [],
    props: {
      valueKey: "id"
    },
    on: {},
    value: "",
    col: {
      span: 4
    }
  };
  selectPosition.on.focus = search(selectPosition);
  return [];
};

export const editRule = () => {
  return [
    {
      type: "hidden",
      hidden: true,
      tableVisible: false,
      title: "ID",
      field: "id",
      value: null
    },
    {
      type: "hidden",
      hidden: true,
      tableVisible: false,
      title: "父节点",
      field: "parent",
      value: null
    },
    {
      type: "input",
      field: "menuName",
      tableVisible: true,
      title: "路由名称(中文)",
      value: ""
    },
    {
      type: "input",
      field: "name",
      tableVisible: true,
      title: "路由名称(英文)",
      value: ""
    },
    {
      type: "input",
      field: "paixu",
      tableVisible: true,
      title: "排序",
      value: ""
    },
    {
      type: "input",
      field: "path",
      tableVisible: true,
      title: "路由地址",
      value: ""
    },
    {
      type: "select",
      field: "isAdmin",
      tableVisible: true,
      title: "是否管理端",
      options: isAdminList(),
      value: "0"
    },
    {
      type: "select",
      field: "layout",
      tableVisible: true,
      options: layoutList(),
      title: "模板",
      value: "",
      control: [
        {
          handle(val) {
            return val == "Dashboard";
          },
          rule: [
            {
              type: "input",
              field: "content",
              title: "content",
              value: ""
            },
            {
              type: "input",
              field: "left",
              title: "left",
              value: ""
            },
            {
              type: "input",
              field: "right",
              title: "right",
              value: ""
            },
            {
              type: "input",
              field: "position",
              tableVisible: true,
              title: "路由位置",
              value: ""
            }
          ]
        }
      ]
    },
    {
      type: "input",
      field: "components",
      tableVisible: true,
      title: "路由组件",
      value: ""
    },
    {
      type: "input",
      field: "meta",
      tableVisible: true,
      title: "标记",
      props: { placeholder: "meta配置" },
      value: ""
    }
  ];
};
